package cn.lqz.bucttrain.controller;

import cn.lqz.bucttrain.annotations.PageQueryAutoFill;
import cn.lqz.bucttrain.pojo.dto.StationPageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.Station;
import cn.lqz.bucttrain.pojo.vo.OrderVO;
import cn.lqz.bucttrain.pojo.vo.PageResultVO;
import cn.lqz.bucttrain.pojo.vo.ResponseVO;
import cn.lqz.bucttrain.service.StationService;
import cn.lqz.bucttrain.utils.ResponseUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/station")
@Validated
public class StationController {
    @Resource
    private StationService stationService;

    @PostMapping("/loadStationList")
    @PageQueryAutoFill
    public ResponseVO<PageResultVO> loadStationList(StationPageQueryDTO stationPageQueryDTO){
        return ResponseUtils.success(stationService.loadStationList(stationPageQueryDTO));
    }

    /**
     * 添加
     * @param station
     * @return
     */
    @PostMapping("/addOrUpdateStation")
    public ResponseVO addOrUpdateStation(@Valid Station station){
        stationService.addOrUpdateStation(station);
        return ResponseUtils.success();
    }

    @PostMapping("/deleteStation")
    public ResponseVO deleteStation(@NotNull Long stationId){
        stationService.deleteStation(stationId);
        return ResponseUtils.success();
    }

    /**
     * 获取站点城市列表
     * @return
     */
    @PostMapping("/loadStationCityList")
    public ResponseVO<List<String>> loadStationCityList(){
        return ResponseUtils.success(stationService.loadStationCityList());
    }
    /**
     * 获取站点名称列表
     * @return
     */
    @PostMapping("/loadStationNameList")
    public ResponseVO<List<String>> loadStationNameList() {
        return ResponseUtils.success(stationService.loadStationNameList());
    }
    /**
     * 导出站点excel表
     * @param stationList
     * @param response
     */
    @PostMapping("/exportStationExcel")
    public void exportStationExcel(@RequestBody List<Station> stationList, HttpServletResponse response){
        stationService.exportStationExcel(stationList,response);
    }
}
